package com.group.dao;

import com.group.model.Out.RebateDetailOut;
import com.group.model.ReferenceWallet;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface InviteRebateDao {

    /*@Select("SELECT r.`refUserId`,a.`name`,a.`headimage`,r.`investment`,r.`rebate`,r.`createDate` FROM referencedetail AS r,USER AS a WHERE a.id = r.`refUserId` AND r.`userId` = #{arg0} GROUP BY r.`userId` ORDER BY createDate DESC limit #{arg1}")
    @Select("SELECT r.`id`,r.`userId`,a.`name`,a.`headimage`,r.`investment`,r.`rebate`,r.`createDate` FROM USER  a, referencedetail r WHERE a.id = r.`userId` AND userId = #{arg0} ORDER BY createDate DESC limit #{arg1}")
    List<RebateDetailOut> getRebateDetail(Long userId, Integer limit);*/

    @Select("SELECT * FROM referencedetail WHERE userId = #{arg0} limit #{arg1}")
    List<RebateDetailOut> getRebateDetail(Long userId, Integer limit);

    @Select("SELECT COUNT(1) FROM referencedetail WHERE userId = #{arg0}")
    Integer getRebateDetailCount(Long userId);

    @Update("UPDATE referencewallet AS rw SET rw.`wallet`= #{arg0},rw.`version` = rw.`version`+1 WHERE userId =#{arg1} AND rw.`version`=#{arg2}")
    Integer updateByVersion(Double fee, Long userId, Integer version);

    @Select("SELECT * FROM referencewallet WHERE userId = #{arg0}")
    ReferenceWallet selectByUserId(Long userId);

    //获取邀请我的人的返佣钱包
    @Select("SELECT * FROM referencewallet WHERE userId = (SELECT refUserId FROM actuser WHERE userId = #{arg0} )")
    ReferenceWallet selectRefUserId(Long userId);
}
